<?php 
	Class emploi_m extends CI_Model
	{

		public function addEmploi()
	    {	
	    	$id_emploi = "GMEM".rand(0,9).rand(0,9).rand(0,9).rand(0,9).rand(0,9).rand(0,9);
	    	if($this->db->select('*')->from('GMEmploi')->where('GMEmploi.GMEM_CODE', $id_emploi)->get())
	    	{
	    		$id_emploi = "GMEM".rand(0,9).rand(0,9).rand(0,9).rand(0,9).rand(0,9).rand(0,9);
	    	}
			$data = array(
							'GMEM_CODE' => $id_emploi,
							'GMET_CODE' =>  $_POST['GMET_CODE'],
							'GMEM_FONCTION' =>  $_POST['GMEM_FONCTION'],
							'GMEM_EMAIL' => $_POST['GMEM_EMAIL'],
							'GMEM_TELEPHONE' => $_POST['GMEM_TELEPHONE'],
							'GMEM_NOM_ENTREPRISE' =>  $_POST['GMEM_NOM_ENTREPRISE'],
							'GMEM_TYPE_CONTRAT' => $_POST['GMEM_TYPE_CONTRAT'],
							'GMEM_DATE_EMBAUCHE' => $_POST['GMEM_DATE_EMBAUCHE'],
							'GMEM_SALAIRE_ANNUEL' => $_POST['GMEM_SALAIRE_ANNUEL'],
							'GMEM_ADRESSE' => $_POST['GMEM_ADRESSE'],
							'GMEM_CODE_POSTAL' => $_POST['GMEM_CODE_POSTAL'],
							'GMEM_VILLE' => $_POST['GMEM_VILLE'],
							'GMEM_PAYS' => $_POST['GMEM_PAYS'],
							'GMEM_NUMERO_ORDRE' => $_POST['GMEM_NUMERO_ORDRE'],
							'GMEM_ACTUEL' => $_POST['GMEM_ACTUEL'],
							'GMEM_DATE_FIN' => $_POST['GMEM_DATE_FIN']					 
    					);
			$this->db->insert('GMEmploi', $data);
		}

		public function editEmploi()
	    {	
			$data = array(
							'GMEM_FONCTION' =>  $_POST['GMEM_FONCTION'],
							'GMEM_EMAIL' => $_POST['GMEM_EMAIL'],
							'GMEM_TELEPHONE' => $_POST['GMEM_TELEPHONE'],
							'GMEM_NOM_ENTREPRISE' =>  $_POST['GMEM_NOM_ENTREPRISE'],
							'GMEM_TYPE_CONTRAT' => $_POST['GMEM_TYPE_CONTRAT'],
							'GMEM_DATE_EMBAUCHE' => $_POST['GMEM_DATE_EMBAUCHE'],
							'GMEM_SALAIRE_ANNUEL' => $_POST['GMEM_SALAIRE_ANNUEL'],
							'GMEM_ADRESSE' => $_POST['GMEM_ADRESSE'],
							'GMEM_CODE_POSTAL' => $_POST['GMEM_CODE_POSTAL'],
							'GMEM_VILLE' => $_POST['GMEM_VILLE'],
							'GMEM_PAYS' => $_POST['GMEM_PAYS'],
							'GMEM_NUMERO_ORDRE' => $_POST['GMEM_NUMERO_ORDRE'],
							'GMEM_ACTUEL' => $_POST['GMEM_ACTUEL'],
							'GMEM_DATE_FIN' => $_POST['GMEM_DATE_FIN']					 
    					);
			$this->db->where('GMEM_CODE', $_POST['GMEM_CODE']);
			$this->db->update('GMEmploi', $data);
		}

		public function getAllEmplois($val)
		{
			$where = array ('GMEtudiant.GMET_CODE' => $val, 'GMEtudiant.GMET_ETAT' => 'ancien');
			$value = $this->db->select('GMEM_CODE, GMEM_FONCTION, GMEM_EMAIL, GMEM_TELEPHONE, GMEM_NOM_ENTREPRISE, GMEM_TYPE_CONTRAT,  GMEM_DATE_EMBAUCHE, GMEM_SALAIRE_ANNUEL, GMEM_ADRESSE, GMEM_CODE_POSTAL, GMEM_VILLE, GMEM_PAYS, GMEM_NUMERO_ORDRE, GMEM_ACTUEL, GMEM_DATE_FIN')->from('GMEmploi')->join('GMEtudiant','GMEmploi.GMET_CODE = GMEtudiant.GMET_CODE')->where($where)->order_by('GMEM_NUMERO_ORDRE','DESC')->get();
			return $value->result();
		}

		public function getEmploi()
		{
			$where = array ('GMEmploi.GMEM_CODE' => $_POST['GMEM_CODE']);
			$value = $this->db->select('*')->from('GMEmploi')->where($where)->get();
			return $value->row();
		}

		public function deleteEmploi()
	    {	
			$where = array(
							'GMEM_CODE' => $_POST['GMEM_CODE']	
    					);
			$this->db->delete('GMEmploi', $where);
		}

	}
?>